package middleware

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"time"
)

func Logger(logger *zap.Logger) gin.HandlerFunc {
	return func(c *gin.Context) {
		start := time.Now()
		c.Next() // 继续执行后续的中间件或路由处理函数
		//latency :=
		logger.Info("Request processed",
			zap.String("method", c.Request.Method),     // 记录请求方法
			zap.String("client_ip", c.ClientIP()),      // 记录客户端IP
			zap.String("path", c.Request.URL.Path),     // 记录请求路径
			zap.Int("status", c.Writer.Status()),       // 记录响应状态码
			zap.Duration("latency", time.Since(start)), // 记录处理时间
		)
	}
}
